package com.xzx.mybatis;

import com.xzx.mybatis.po.Blog;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author xinzhixuan
 * @version 1.0
 * @date 2025/5/30 18:46
 */
public class BuildSqlSessionFactoryByXmlMain {
    public static void main(String[] args) throws IOException {
       InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        Blog blog = sqlSession.selectOne("com.xzx.BlogMapper.selectBlog", 1);
        System.out.println(blog);
        sqlSession.close();
    }
}